package com.zc.ex.userProvider.controller;

import com.zc.ex.userProvider.common.BaseResult;
import com.zc.ex.userProvider.dto.UserInfoQueryDTO;
import com.zc.ex.userProvider.model.UserInfo;
import com.zc.ex.userProvider.server.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api("用户信息")
@RestController
public class UserController {
    @Resource
    private UserService userService;

    @ApiOperation("添加用户")
    @ResponseBody
    @PostMapping("/user/add")
    public BaseResult<UserInfo> addUser(@RequestBody UserInfo userInfo){
        return userService.addUserInfo(userInfo);
    }

    @ApiOperation("更新用户")
    @ResponseBody
    @PostMapping("/user/update")
    public BaseResult<UserInfo> updateUser(@RequestBody UserInfo userInfo){
        return userService.updateUserInfo(userInfo);
    }

    @ApiOperation("查询用户")
    @ResponseBody
    @GetMapping("/user/query")
    public BaseResult<List<UserInfo>> queryUserInfo(@RequestBody UserInfoQueryDTO queryDTO){
        return userService.queryUserInfo(queryDTO);
    }

    @ApiOperation(value = "删除用户",notes = "根据用户的ID来删除对应的用户数据")
    @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long")
    @ResponseBody
    @DeleteMapping("/user/del")
    public BaseResult delUserInfo(@RequestParam("id")Long id){
        return userService.delUserInfo(id);
    }
}
